/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author tashiba
 */
public class PengendaliSekretariat {

    public static String nama = "Daftar Mahasiswa ";
    public static ArrayList<Yudisium> DAFTAR_MAHASISWA = new ArrayList<Yudisium>();


 public static void bacaTabelMahasiswa(){

       DAFTAR_MAHASISWA= new ArrayList<Yudisium>();
       Connection conn = OraConnection.open("jdbc:oracle:thin:@localhost:1521:xe","elsa", "115314011");
        java.sql.Statement statement = null;
        try {
            statement = conn.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliMahasiswa.class.getName()).log(Level.SEVERE, null, ex);
        }
       String sql = "select * from MAHASISWA";
       ResultSet result = null;
        try {
            result = statement.executeQuery(sql);
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliMahasiswa.class.getName()).log(Level.SEVERE, null, ex);
        }


        try {
            while (result.next()) {
                Yudisium temp = new Yudisium() {

                    public int hitungDenda(int lamaPinjam) {
                        throw new UnsupportedOperationException("Not supported yet.");
                    }
                };
                try {
                    temp.setNim(result.getString("NIM"));
                } catch (Exception ex) {
                    Logger.getLogger(PengendaliMahasiswa.class.getName()).log(Level.SEVERE, null, ex);
                }
                temp.setNama(result.getString("NAMA"));
                temp.setProdi(result.getString("PRODI"));
                temp.setPeriode(result.getString("PERIODE"));
                DAFTAR_MAHASISWA.add(temp);
                }
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliSekretariat.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
  public static ArrayList<Yudisium> cariMahasiswa(String periode, String hari , String tanggal) {
        ArrayList<Yudisium> hasil = new ArrayList<Yudisium>();
        for (int i = 0; i < DAFTAR_MAHASISWA.size(); i++) {
            Yudisium temp = DAFTAR_MAHASISWA.get(i);
            if (temp.getPeriode().contains(periode)&& temp.getHari().contains(hari)&& temp.getTanggal().contains(tanggal)) {
                hasil.add(temp);
            }
        }
        return hasil;
    }
}

